package ccgl.com.action;

import java.io.IOException;
import java.text.ParseException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ccgl.com.model.MUser;
import ccgl.com.server.XxtjServer;
import ccgl.com.util.GsonPrint;

/**
 * 信息统计 Action
 * 
 * @author qw
 * 
 */
public class XxtjAction extends BaseServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	HttpServletRequest request = null;
	HttpServletResponse response = null;
	XxtjServer server = new XxtjServer();
	private String charset = "text/html; charset=gbk";

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		this.request = req;
		this.response = resp;
		req.setCharacterEncoding("UTF-8");
		String control = this.request.getParameter("control");
		if ("getLineDate".equals(control)) {
			getLineDate();
		} else {
			GsonPrint.printFormatGson("没有请求的control！", this.response);
		}
	}

	/**
	 * 返回折线图数据
	 */
	private void getLineDate() {
		String tjStar = this.request.getParameter("tjStar");
		String tjEnd = this.request.getParameter("tjEnd");
		String timeLimit = this.request.getParameter("timeLimit");
		String userId = ((MUser) this.request.getSession().getAttribute("user"))
				.getId();
		try {
			GsonPrint.printData(
					server.getLineDate(tjStar, tjEnd, timeLimit, userId),
					charset, response);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
}
